package b3.widget.home.town
{
	import b3.model.*;
	import b3.net.*;
	import b3.scene.home.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;
	import flash.utils.*;

	public class OccupantPane extends BasicWidget
	{
		private var occupantText:TextField;
		
		public function OccupantPane()
		{
			super();
			//背景
			var OccupantPaneBgr:Class = ResourceHelper.getInstance().getClassByName("OccupantPaneBgr");
			var occupantPaneBgr:Sprite = new OccupantPaneBgr();
			addChild(occupantPaneBgr);
			//占领者
			var occupantTitle:TextField = new TextField();
			occupantTitle.selectable = false;
			occupantTitle.autoSize = TextFieldAutoSize.LEFT;
			occupantTitle.defaultTextFormat = new TextFormat("微软雅黑", 10, 0x000000);
			occupantTitle.text = "当前城市占领者";
			occupantTitle.x = 62;
			occupantTitle.y = 22;
			addChild(occupantTitle);
			occupantText = new TextField();
			occupantText.selectable = false;
			occupantText.autoSize = TextFieldAutoSize.CENTER;
			occupantText.defaultTextFormat = new TextFormat("微软雅黑", 10, 0x000000, true);
//			occupantText.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			occupantText.x = 95;
			occupantText.y = 34;
			addChild(occupantText);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.addEventListener(MouseEvent.CLICK, onMouseClick);
			var pm:PlayerManager = PlayerManager.getInstance(); 
			pm.addEventListener(ModelEvent.SWITCH_PLAYER, onRefresh);
			this.mouseChildren = false;
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			AttackIcon.onMouseClick(event);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			var container:Sprite = new Sprite();		
			//提示图标
			var OperationAttack:Class = ResourceHelper.getInstance().getClassByName("OccupantIcon");
			var tipIcon:Sprite = new OperationAttack();
			tipIcon.height = 60;
			tipIcon.scaleX = tipIcon.scaleY;
			tipIcon.x = 10;
			tipIcon.y = 0;
			container.addChild(tipIcon);
			//提示信息
			var town:Town = HomeScene.getInstance().getCurrentTown();
			var tipText:TextField = new TextField();
			tipText.selectable = false;
			tipText.autoSize = TextFieldAutoSize.LEFT;
			tipText.defaultTextFormat = new TextFormat("微软雅黑", 25, 0xFFFFFF, true);
			tipText.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			tipText.text = "攻击最高楼，抢占该城市";
			tipText.x = 80;
			tipText.y = 0;
			container.addChild(tipText);
			//说明信息
			var directionText:TextField = new TextField();
			directionText.selectable = false;
			directionText.autoSize = TextFieldAutoSize.LEFT;
			directionText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			directionText.text = "（点击定位最高楼）";
			directionText.x = tipText.x + Math.max((tipText.width - directionText.width) / 2, 0);
			directionText.y = 40;
			container.addChild(directionText);
			HomeScene.getInstance().centerInfoPane.showInfo(container);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
			Mouse.cursor = "auto";
		}
		
		private function onRefresh(event:ModelEvent):void
		{
			var town:Town = HomeScene.getInstance().getCurrentTown();
			if (town.owner.occupantName != null)
				occupantText.text = town.owner.occupantName;
			else
				occupantText.text = "匿名用户";
		}
		
		public function setOccupant(occupantId:int):void
		{
			var occupant:Player = PlayerManager.getInstance().players[occupantId];
			if (occupant != null)
			{
				occupantText.text = occupant.name;
			}
			else
			{
				occupantText.text = "匿名用户";
			}
		}
		
	}
}